<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="入库单号" prop="jtdm">
        <el-input
          v-model="queryParams.jtdm"
          placeholder="请输入集团代码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="子图号" prop="jtmc">
        <el-input
          v-model="queryParams.jtmc"
          placeholder="请输入集团名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['hr:orgManage:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['hr:orgManage:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['hr:orgManage:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="info"
          plain
          icon="el-icon-upload2"
          size="mini"
          @click="handleImport"
        >导入</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['hr:orgManage:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="orgManageList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="计划号" align="center" prop="jtmc" />
      <el-table-column label="出库单号" align="center" prop="ejdwjc" />
      <el-table-column width="120" label="业务类型" align="center" prop="ejdwdz" />
      <el-table-column width="120" label="子图号" align="center" prop="ejdwdz" />
      <el-table-column label="物料名称" align="center" prop="ejdwdz" />
      <el-table-column label="组别" align="center" prop="ejdwdh" />
      <el-table-column label="批次" align="center" prop="ejdwsh" />
      <el-table-column label="托管属性" align="center" prop="ejdwsh" />
      <el-table-column label="质量状态" align="center" prop="ejdwsh" />
      <el-table-column label="库位编码" align="center" prop="ejdwsh" />
      <el-table-column width="120" label="计划出库数量" align="center" prop="ejdwsh" />
      <el-table-column width="120" label="实际出库数量" align="center" prop="ejdwsh" />
      <el-table-column label="状态" align="center" prop="ejdwsh" />
      <el-table-column label="wzk单号" align="center" prop="ejdwsh" />
      <el-table-column width="150" label="总装入库回写wzk状态" align="center" prop="ejdwsh" />
      <el-table-column width="150" label="总装入库回写wzk时间" align="center" prop="ejdwsh" />
      <el-table-column width="150" label="总装入库回写wzk备注" align="center" prop="ejdwsh" />
      <el-table-column width="120" label="总装入库人" align="center" prop="ejdwsh" />
      <el-table-column width="120" label="总装入库数" align="center" prop="ejdwsh" />
      <el-table-column width="120" label="托盘码" align="center" prop="ejdwsh" />
      <el-table-column width="120" label="物料条形码" align="center" prop="ejdwsh" />
      <el-table-column label="供应商" align="center" prop="ejdwsh" />
      <el-table-column width="120" label="供应商代码" align="center" prop="ejdwsh" />
      <el-table-column label="拣货人" align="center" prop="ejdwsh" />
      <el-table-column label="拣货时间" align="center" prop="ejdwsh" />
      <el-table-column width="120" label="配送条形码" align="center" prop="ejdwsh" />
      <el-table-column label="配送时间" align="center" prop="ejdwsh" />
      <el-table-column width="120" label="单据创建时间" align="center" prop="ejdwsh" />
      <el-table-column width="120" label="拣货工位段" align="center" prop="ejdwsh" />
      <el-table-column width="150" label="条码打印次数" align="center" prop="ejdwsh" />
      <el-table-column width="150" label="出库单打印次数" align="center" prop="ejdwsh" />
      <el-table-column width="150" label="CKD单据打印次数" align="center" prop="ejdwsh" />
      <el-table-column label="器具号" align="center" prop="ejdwsh" />
      <el-table-column label="备注" align="center" prop="ejdwsh" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['hr:orgManage:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['hr:orgManage:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改组织机构管理对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="集团代码" prop="jtdm">
          <el-input v-model="form.jtdm" placeholder="请输入集团代码" />
        </el-form-item>
        <el-form-item label="集团名称" prop="jtmc">
          <el-input v-model="form.jtmc" placeholder="请输入集团名称" />
        </el-form-item>
        <el-form-item label="二级单位简称" prop="ejdwjc">
          <el-input v-model="form.ejdwjc" placeholder="请输入二级单位简称" />
        </el-form-item>
        <el-form-item label="二级单位地址" prop="ejdwdz">
          <el-input v-model="form.ejdwdz" placeholder="请输入二级单位地址" />
        </el-form-item>
        <el-form-item label="二级单位电话" prop="ejdwdh">
          <el-input v-model="form.ejdwdh" placeholder="请输入二级单位电话" />
        </el-form-item>
        <el-form-item label="二级单位税号" prop="ejdwsh">
          <el-input v-model="form.ejdwsh" placeholder="请输入二级单位税号" />
        </el-form-item>
        <el-form-item label="二级单位开户行" prop="ejdwkhx">
          <el-input v-model="form.ejdwkhx" placeholder="请输入二级单位开户行" />
        </el-form-item>
        <el-form-item label="二级单位账号" prop="ejdwzh">
          <el-input v-model="form.ejdwzh" placeholder="请输入二级单位账号" />
        </el-form-item>
        <el-form-item label="三级单位代码" prop="sjdwdm">
          <el-input v-model="form.sjdwdm" placeholder="请输入三级单位代码" />
        </el-form-item>
        <el-form-item label="三级单位名称" prop="sjdwmc">
          <el-input v-model="form.sjdwmc" placeholder="请输入三级单位名称" />
        </el-form-item>
        <el-form-item label="三级单位简称" prop="sjdwjc">
          <el-input v-model="form.sjdwjc" placeholder="请输入三级单位简称" />
        </el-form-item>
        <el-form-item label="三级单位地址" prop="sjdwdz">
          <el-input v-model="form.sjdwdz" placeholder="请输入三级单位地址" />
        </el-form-item>
        <el-form-item label="集团简称" prop="jtjc">
          <el-input v-model="form.jtjc" placeholder="请输入集团简称" />
        </el-form-item>
        <el-form-item label="三级单位电话" prop="sjdwdh">
          <el-input v-model="form.sjdwdh" placeholder="请输入三级单位电话" />
        </el-form-item>
        <el-form-item label="三级单位税号" prop="sjdwsh">
          <el-input v-model="form.sjdwsh" placeholder="请输入三级单位税号" />
        </el-form-item>
        <el-form-item label="三级单位开户行" prop="sjdwkhx">
          <el-input v-model="form.sjdwkhx" placeholder="请输入三级单位开户行" />
        </el-form-item>
        <el-form-item label="三级单位账号" prop="sjdwzh">
          <el-input v-model="form.sjdwzh" placeholder="请输入三级单位账号" />
        </el-form-item>
        <el-form-item label="部门代码" prop="bmdm">
          <el-input v-model="form.bmdm" placeholder="请输入部门代码" />
        </el-form-item>
        <el-form-item label="部门名称" prop="bmmc">
          <el-input v-model="form.bmmc" placeholder="请输入部门名称" />
        </el-form-item>
        <el-form-item label="公司代码" prop="gcdm">
          <el-input v-model="form.gcdm" placeholder="请输入公司代码" />
        </el-form-item>
        <el-form-item label="公司简码" prop="gcjm">
          <el-input v-model="form.gcjm" placeholder="请输入公司简码" />
        </el-form-item>
        <el-form-item label="公司名称" prop="gcmc">
          <el-input v-model="form.gcmc" placeholder="请输入公司名称" />
        </el-form-item>
        <el-form-item label="公司地址" prop="gcdz">
          <el-input v-model="form.gcdz" placeholder="请输入公司地址" />
        </el-form-item>
        <el-form-item label="集团地址" prop="jtdz">
          <el-input v-model="form.jtdz" placeholder="请输入集团地址" />
        </el-form-item>
        <el-form-item label="公司电话" prop="gcdh">
          <el-input v-model="form.gcdh" placeholder="请输入公司电话" />
        </el-form-item>
        <el-form-item label="公司税号" prop="gcsh">
          <el-input v-model="form.gcsh" placeholder="请输入公司税号" />
        </el-form-item>
        <el-form-item label="公司开户行" prop="gckhx">
          <el-input v-model="form.gckhx" placeholder="请输入公司开户行" />
        </el-form-item>
        <el-form-item label="公司账号" prop="gczh">
          <el-input v-model="form.gczh" placeholder="请输入公司账号" />
        </el-form-item>
        <el-form-item label="分部代码" prop="fbdm">
          <el-input v-model="form.fbdm" placeholder="请输入分部代码" />
        </el-form-item>
        <el-form-item label="分部名称" prop="fbmc">
          <el-input v-model="form.fbmc" placeholder="请输入分部名称" />
        </el-form-item>
        <el-form-item label="分公司代码" prop="fgcdm">
          <el-input v-model="form.fgcdm" placeholder="请输入分公司代码" />
        </el-form-item>
        <el-form-item label="分公司名称" prop="fgcmc">
          <el-input v-model="form.fgcmc" placeholder="请输入分公司名称" />
        </el-form-item>
        <el-form-item label="生产线代码" prop="scxdm">
          <el-input v-model="form.scxdm" placeholder="请输入生产线代码" />
        </el-form-item>
        <el-form-item label="生产线编号" prop="scxbh">
          <el-input v-model="form.scxbh" placeholder="请输入生产线编号" />
        </el-form-item>
        <el-form-item label="集团电话" prop="jtdh">
          <el-input v-model="form.jtdh" placeholder="请输入集团电话" />
        </el-form-item>
        <el-form-item label="生产线编码" prop="scxbm">
          <el-input v-model="form.scxbm" placeholder="请输入生产线编码" />
        </el-form-item>
        <el-form-item label="生产线名称" prop="scxmc">
          <el-input v-model="form.scxmc" placeholder="请输入生产线名称" />
        </el-form-item>
        <el-form-item label="分装类型" prop="fzlx">
          <el-input v-model="form.fzlx" placeholder="请输入分装类型" />
        </el-form-item>
        <el-form-item label="分装线代码" prop="fzxdm">
          <el-input v-model="form.fzxdm" placeholder="请输入分装线代码" />
        </el-form-item>
        <el-form-item label="分装线名称" prop="fzxmc">
          <el-input v-model="form.fzxmc" placeholder="请输入分装线名称" />
        </el-form-item>
        <el-form-item label="班组代码" prop="bzdm">
          <el-input v-model="form.bzdm" placeholder="请输入班组代码" />
        </el-form-item>
        <el-form-item label="班组名称" prop="bzmc">
          <el-input v-model="form.bzmc" placeholder="请输入班组名称" />
        </el-form-item>
        <el-form-item label="岗位代码" prop="gwdm">
          <el-input v-model="form.gwdm" placeholder="请输入岗位代码" />
        </el-form-item>
        <el-form-item label="岗位名称" prop="gwmc">
          <el-input v-model="form.gwmc" placeholder="请输入岗位名称" />
        </el-form-item>
        <el-form-item label="包装费用" prop="bzfy">
          <el-input v-model="form.bzfy" placeholder="请输入包装费用" />
        </el-form-item>
        <el-form-item label="集团税号" prop="jtsh">
          <el-input v-model="form.jtsh" placeholder="请输入集团税号" />
        </el-form-item>
        <el-form-item label="料废损失金额" prop="lfssje">
          <el-input v-model="form.lfssje" placeholder="请输入料废损失金额" />
        </el-form-item>
        <el-form-item label="合计费用" prop="hjfy">
          <el-input v-model="form.hjfy" placeholder="请输入合计费用" />
        </el-form-item>
        <el-form-item label="集团开户行" prop="jtkhx">
          <el-input v-model="form.jtkhx" placeholder="请输入集团开户行" />
        </el-form-item>
        <el-form-item label="集团账号" prop="jtzh">
          <el-input v-model="form.jtzh" placeholder="请输入集团账号" />
        </el-form-item>
        <el-form-item label="二级单位代码" prop="ejdwdm">
          <el-input v-model="form.ejdwdm" placeholder="请输入二级单位代码" />
        </el-form-item>
        <el-form-item label="二级单位名称" prop="ejdwmc">
          <el-input v-model="form.ejdwmc" placeholder="请输入二级单位名称" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <el-dialog :close-on-click-modal="false" :title="upload.title" :visible.sync="upload.open" width="400px" append-to-body>
      <el-upload
        ref="upload"
        :limit="1"
        accept=".xlsx, .xls"
        :headers="upload.headers"
        :action="upload.url + '?updateSupport=' + upload.updateSupport"
        :disabled="upload.isUploading"
        :on-progress="handleFileUploadProgress"
        :on-success="handleFileSuccess"
        :auto-upload="false"
        drag
      >
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
        <div class="el-upload__tip text-center" slot="tip">
          <!--  <div class="el-upload__tip" slot="tip">
              <el-checkbox v-model="upload.updateSupport" /> 是否更新已经存在的用户数据
            </div>-->
          <span>仅允许导入xls、xlsx格式文件。</span>
          <el-link type="primary" :underline="false" style="font-size:12px;vertical-align: baseline;" @click="importTemplate">下载模板</el-link>
        </div>
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFileForm">确 定</el-button>
        <el-button @click="upload.open = false">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import { listOrgManage, getOrgManage, delOrgManage, addOrgManage, updateOrgManage } from "@/api/hr/orgManage";
  import {getToken} from "@/utils/auth";

  export default {
    name: "OrgManage",
    data() {
      return {
        // 遮罩层
        loading: false,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 组织机构管理表格数据
        orgManageList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
        },
        // 表单参数
        form: {},
        upload: {
          // 是否显示弹出层（物料导入）
          open: false,
          // 弹出层标题（物料导入）
          title: "导入数据",
          // 是否禁用上传
          isUploading: false,
          // 是否更新已经存在的用户数据
          updateSupport: 0,
          // 设置上传的请求头部
          headers: { Authorization: "Bearer " + getToken() },
          // 上传的地址
          url: process.env.VUE_APP_BASE_API + "/hr/orgManage/importData"
        },
        // 表单校验
        rules: {
        }
      };
    },
    created() {
      this.getList();
    },
    methods: {
      /** 查询组织机构管理列表 */
      getList() {
        //this.loading = true;
        // listOrgManage(this.queryParams).then(response => {
        //   this.orgManageList = response.rows;
        //   this.total = response.total;
        //   this.loading = false;
        // });
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {
        };
        this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.id)
        this.single = selection.length!==1
        this.multiple = !selection.length
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.reset();
        this.open = true;
        this.title = "添加组织机构管理";
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        this.reset();
        const id = row.id || this.ids
        // getOrgManage(id).then(response => {
        //   this.form = response.data;
        //   this.open = true;
        //   this.title = "修改组织机构管理";
        // });
      },
      /** 提交按钮 */
      submitForm() {
        this.$refs["form"].validate(valid => {
          if (valid) {
            // if (this.form.id != null) {
            //   updateOrgManage(this.form).then(response => {
            //     this.$modal.msgSuccess("修改成功");
            //     this.open = false;
            //     this.getList();
            //   });
            // } else {
            //   addOrgManage(this.form).then(response => {
            //     this.$modal.msgSuccess("新增成功");
            //     this.open = false;
            //     this.getList();
            //   });
            // }
          }
        });
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const ids = row.id || this.ids;
        this.$modal.confirm('是否确认删除组织机构管理编号为"' + ids + '"的数据项？').then(function() {
          return delOrgManage(ids);
        }).then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        }).catch(() => {});
      },
      /** 导出按钮操作 */
      handleExport() {
        this.download('hr/orgManage/export', {
          ...this.queryParams
        }, `orgManage_${new Date().getTime()}.xlsx`)
      },
      /** 导入按钮操作 */
      handleImport() {
        this.upload.title = "数据导入";
        this.upload.open = true;
      },
      /** 下载模板操作 */
      importTemplate() {
        this.download('hr/orgManage/importTemplate', {
        }, `组织机构模板.xlsx`)
      },
      // 文件上传中处理
      handleFileUploadProgress(event, file, fileList) {
        this.upload.isUploading = true;
      },
      // 文件上传成功处理
      handleFileSuccess(response, file, fileList) {
        this.upload.open = false;
        this.upload.isUploading = false;
        this.$refs.upload.clearFiles();
        this.$alert("<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" + response.msg + "</div>", "导入结果", { dangerouslyUseHTMLString: true });
        this.getList();
      },
      // 提交上传文件
      submitFileForm() {
        this.$refs.upload.submit();
      }
    }
  };
</script>
